package com.ruoyi.web.controller.nongjt.Linkedlist;

// NjtAreaController.java


import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.nongjt.domain.pojo.NjtProvince;
import com.ruoyi.nongjt.domain.pojo.NjtCity;
import com.ruoyi.nongjt.domain.pojo.NjtDistrict;
import com.ruoyi.nongjt.service.NjtAreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

@RestController
@RequestMapping("/nongjt/area")
public class NjtAreaController extends BaseController {

    @Autowired
    private NjtAreaService areaService;

    /**
     * 获取所有省份
     */
    @GetMapping("/provinces")
    public AjaxResult getAllProvinces() {
        List<NjtProvince> provinces = areaService.getAllProvinces();
        return AjaxResult.success(provinces);
    }

    /**
     * 根据省份ID获取城市列表
     */
    @GetMapping("/cities")
    public AjaxResult getCitiesByProvinceId(@RequestParam Integer provinceId) {
        List<NjtCity> cities = areaService.getCitiesByProvinceId(provinceId);
        return AjaxResult.success(cities);
    }

    /**
     * 根据城市ID获取区县列表
     */
    @GetMapping("/districts")
    public AjaxResult getDistrictsByCityId(@RequestParam Integer cityId) {
        List<NjtDistrict> districts = areaService.getDistrictsByCityId(cityId);
        return AjaxResult.success(districts);
    }
}
